package com.ccc.demoboot.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccc.demoboot.pojo.Der;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccc.demoboot.dao.DerMapper;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author wz
 * @Date 2024/6/4 9:01
 * @PackageName:com.ccc.demoboot.service
 * @ClassName: DerServiceImpl
 */
@Service
public class DerServiceImpl extends ServiceImpl<DerMapper, Der> implements DerService {

    @Override
    public List<Map<String, Object>> selectAllDer(QueryWrapper queryWrapper, int status, int applyuserid) {
        return this.baseMapper.selectAllDer(queryWrapper, status, applyuserid);
    }

    @Override
    public boolean batAddDer(List<Der> list) {

        for (Der der : list) {
            der.setBatchid(Calendar.getInstance().getTimeInMillis() + "");
        }

        return this.baseMapper.batAddDer(list);
    }

    @Override
    public List<Map<String, Object>> selectOne(String batchid) {
        return this.baseMapper.selectOne(batchid);
    }

    @Override
    public boolean uniAddDer(Map<String, Object> map,int deruserid) {
        List<Map<String, Object>> materialList = (List<Map<String, Object>>) map.get("materialList");
        String batchid = Calendar.getInstance().getTimeInMillis() + "";
        Date applicationtime=new Date();
        int result=1;
        boolean b=false;
        for (Map<String, Object> stringObjectMap : materialList) {
            Der der = new Der();
            der.setBatchid(batchid);
            der.setDeruserid(deruserid);
            der.setApplicationtime(applicationtime);
            der.setMaterialid((Integer) stringObjectMap.get("materialid"));
            der.setContent((Integer) stringObjectMap.get("content"));
            result=this.baseMapper.insert(der);
        }
        if(result==1){
            return true;
        }
        return false;
    }

    @Override
    public List<Map<String,Object>> selectDerAll() {

        return this.baseMapper.selectDerAll();
    }
}
